﻿/* 09. Write a method that return the maximal element in a portion of array of integers starting at given index. 
 * Using it write another method that sorts an array in ascending / descending order. */

using System;
using System.Text;

public class MaxElementInPortionOfArray
{
    public static int[] array;

    public static void Main()
    {
        int index;
        StringBuilder description = new StringBuilder();

        array = Common.InputArray(array, "");
        description.Append(Common.InputArrayDescription(array, "") + "Starting index: ");

        do
        {
            index = Common.InputNonNegativeInteger(description.ToString());
        } while (array.Length <= index);

        Console.WriteLine("\nThe maximal element in portion of this array starting at index {0} is {1}\n",
            index, MaxElementInPortion(index, array));
    }

    public static int MaxElementInPortion(int index, int[] array)
    {
        Array.Sort(array, index, array.Length - index);
        return array[array.Length - 1];
    }
}